<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form binding="#{salesOrderManagerBean.loadMySalesOrders}">
                    <p:panel header="Customer Details" id="customerDetailsPanel">
                        <table width="100%" border="0">
                            <tr>
                                <td width="200px">
                                    Company:
                                </td>
                                <td>
                                    <h:outputText id="company" value="#{salesOrderManagerBean.selectedCustomer.company}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Description:
                                </td>
                                <td>
                                    <h:outputText id="description" value="#{salesOrderManagerBean.selectedCustomer.description}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Annual Revenue:
                                </td>
                                <td>
                                    <h:outputText id="revenue" value="#{salesOrderManagerBean.selectedCustomer.revenue}">
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Number of Employees:
                                </td>
                                <td>
                                    <h:outputText id="numEmployee" value="#{salesOrderManagerBean.selectedCustomer.numEmployee}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Contact Person
                                </td>
                                <td>
                                    <h:outputText id="contactPerson" value="#{salesOrderManagerBean.selectedCustomer.firstName}, 
                                                  #{salesOrderManagerBean.selectedCustomer.lastName}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Designation:
                                </td>
                                <td>
                                    <h:outputText id="title" value="#{salesOrderManagerBean.selectedCustomer.title}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Contact Number:
                                </td>
                                <td>
                                    <h:outputText id="phone" value="#{salesOrderManagerBean.selectedCustomer.phone}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Credit Rank:
                                </td>
                                <td>
                                    <h:outputText id="rank" value="#{salesOrderManagerBean.selectedCustomer.credit.creditRank}" />
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <p:panel header="Sales Orders" id="salesOrdersPanel">
                        <p:dataTable id="mySalesOrders" var="orderItem" value="#{salesOrderManagerBean.salesOrders}" 
                                     emptyMessage="No sales orders found with given criteria."
                                     selection="#{salesOrderManagerBean.selectedSalesOrder}"
                                     selectionMode="single"
                                     rowSelectListener="#{salesOrderManagerBean.onRowSelect}"
                                     onRowSelectUpdate="eventsPanel" 
                                     rowUnselectListener="#{salesOrderManagerBean.onRowUnselect}"
                                     onRowUnselectUpdate="eventsPanel">
                            <p:column filterBy="#{orderItem.job.purchaseOrder.id}" headerText="PO ID" 
                                      filterMatchMode="contains" sortBy="#{orderItem.job.purchaseOrder.id}">  
                                <h:outputText value="#{orderItem.job.purchaseOrder.id}"/> 
                            </p:column> 
                            <p:column headerText="Total Amount" sortBy="#{orderItem.job.purchaseOrder.totalAmount}">  
                                <h:outputText value="#{orderItem.job.purchaseOrder.totalAmount}">  
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Credit Rate (%)" sortBy="#{orderItem.job.purchaseOrder.creditRate}">  
                                <h:outputText value="#{orderItem.job.purchaseOrder.creditRate}">
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Status" sortBy="#{orderItem.status}">  
                                <h:outputText value="#{orderItem.status}">
                                </h:outputText>
                            </p:column> 
                        </p:dataTable>
                    </p:panel>
                    <p:panel header="Events" id="eventsPanel">
                        <p:dataTable id="eventItems" var="eventItem" value="#{salesOrderManagerBean.trackingItems}" 
                                     emptyMessage="No events found with given criteria.">
                            <p:column headerText="Event Date">  
                                <h:outputText value="#{eventItem.creationDate}"> 
                                    <f:convertDateTime pattern="dd-MM-yyyy hh:mm a" timeZone="#{defaultManagerBean.tz}"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Description">  
                                <h:outputText value="#{eventItem.description}"> 
                                </h:outputText>
                            </p:column> 
                        </p:dataTable>
                    </p:panel>
                    <p:commandButton id="btnBackFromMySalesOrders" value="Back" 
                                     title="Go back to previous page."
                                     actionListener="#{salesOrderManagerBean.back}"
                                     ajax="true"/>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
